<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Flickr extends CI_Controller {

	public function __construct()
	{
		parent::__construct();
	}
	
	public function get_images()
	{
		$lat0 	= $this->input->post('y')-$this->input->post('size');
		$long0 	= $this->input->post('x')-$this->input->post('size');
		$lat1 	= $this->input->post('y')+$this->input->post('size');
		$long1 	= $this->input->post('x')+$this->input->post('size');
		
		require_once("phpFlickr.php");
	
		$key    = "c9db0f699b325251e6ebf92d13f8a8ea";
		$secret = "b3c4c56300dd2246";
	
		$f = new phpFlickr($key, $secret, true);
		$f->enableCache("fs", "cache");
	
		//$date['start'] = date("Y-m-d H:i:s", strtotime($_REQUEST['date_start']));
		//$date['end'] = date("Y-m-d H:i:s", strtotime($_REQUEST['date_end']));
		//print_r($date);
		//echo '<br/>';
	
		$photos = $f->photos_search(array(
	                            //"min_taken_date"  => $date['start'],
	                            //"max_taken_date"  => $date['end'],
	                            "sort"  => "interestingness-desc",
	                            "bbox"  => $lat0.','.$long0.','.$lat1.','.$long1,
	                            "extras"  => "date_taken,date_upload,geo,tags"
		));
	
		//echo '<!--';
		//print_r($photos);
		//echo '-->';
	
		//echo "count: ".count($photos['photo']).'<br/>';
		echo "<ul>";
		foreach($photos['photo'] as $photo) {
			$owner = $f->people_getInfo($photo['owner']);
			$url = 'http://farm'.$photo['farm'].'.static.flickr.com/'.$photo['server'].'/'.$photo['id'].'_'.$photo['secret'].'_m.jpg';
			echo '
			<li>
			<img onClick="flickr_url(\''.$url.'\');" style="cursor: pointer;" src="'.$url.'"/>
			</li>';
		}
		echo "</ul>";
	}
}

/* End of file flickr.php */
/* Location: ./application/controllers/flickr.php */